<template>
  <van-nav-bar class="header" to="/order" :fixed="true" title="" left-text="确认订单" left-arrow
    @click-left="onClickLeft" />
  <div class="user">
    <van-icon class="left" name="location-o" />
    <div class="middle">
      <p>{{ address.list[idx].address }}</p>
      <div class="flex">
        <p>{{ address.list[idx].name }}</p>
        <p>{{ address.list[idx].tel }}</p>
      </div>
    </div>
    <van-icon class="right" name="arrow" @click="handleEidt" />
  </div>

  <div class="time">
    <div class="tip">温馨提示30分钟内未付款订单将自动取消</div>
  </div>

  <div class="limit">
    <van-icon class="left" name="clock-o" />
    <div class="middle">立即送出</div>
    <van-icon class="right" name="arrow" />
  </div>
  <div class="empty"></div>

  <!-- 渲染订单 -->
  <van-list finished-text="没有更多了" @load="onLoad">
    <p class="orderDel">订单详情</p>
    <van-card v-for="item in Order.list" :num="item.n" :price="item.price" desc="描述信息" :title="item.name"
      :thumb="item.img" />
  </van-list>

  <div class="bbox">
    <div class="box">
      <div class="flex1">
        <p>包装费</p>
        <p>￥3</p>
      </div>
      <div class="flex1">
        <p>配送费</p>
        <p>￥2</p>
      </div>
    </div>
  </div>

  <div class="bbox">
    <div class="box">
      <div class="flex1">
        <p>配送费<span class="red">(满80免配送费)</span></p>
        <p>-￥3</p>
      </div>
      <div class="flex1">
        <p>优惠券</p>

        <p class="gray">无可用
          <van-icon class="right" name="arrow" />
        </p>
      </div>
    </div>
  </div>

  <div class="box2">
    <div class="Allprice">
      <div>共{{ Order.cartAllInfo.allNum }}件,&nbsp;&nbsp;小计<span class="red">￥{{
        Order.cartAllInfo.Allprice / 100
      }}</span>
      </div>
    </div>
  </div>
  <div class="empty"></div>

  <van-radio-group v-model="checked">
    <div class="bbox">
      <div class="box">
        <div class="flex1">
          <p>
            <van-icon class="icon" name="wechat-pay" color="green" />
            微信支付
          </p>
          <p>
            <van-radio name="1" icon-size="24px"></van-radio>
          </p>
        </div>
        <div class="flex1">
          <p>
            <van-icon class="icon" name="gold-coin" color="yellow" />
            <span> 会员钱包支付</span>
          </p>
          <p>
            <van-radio name="2" icon-size="24px"></van-radio>
          </p>
        </div>
        <div class="flex1">
          <p>开票方式</p>
          <p class="gray">餐厅提供电子发条</p>
        </div>
      </div>
    </div>
  </van-radio-group>

  <div class="eject">
    <div class="box">
      <van-action-sheet v-model:show="show" :actions="actions" cancel-text="取消" close-on-click-action @cancel="onCancel"
        @select="onSelect" />
      <div>
        <div class="flex1">
          <p>餐具数量</p>
          <p class="gray" @click="handleShow">{{ name== null ? '选择' : name }}
            <van-icon v-model="show" class="right" name="arrow" />
          </p>
        </div>
      </div>
      <div>
        <p class="request">其他需求</p>
        <van-cell-group inset>
          <van-field class="message" v-model="message" rows="2" autosize label="" type="textarea" maxlength="50"
            placeholder="请输入你的其它需求" show-word-limit />
        </van-cell-group>
      </div>
    </div>
  </div>
  <van-action-sheet v-model:show="show1" title="">
    <div class="content">
      <van-button @click="handleSuc" type="success">支付成功</van-button>
      <van-button @click="handleFal" type="warning">支付失败</van-button>
    </div>
  </van-action-sheet>
  <van-submit-bar :price="Order.cartAllInfo.Allprice" button-text="立即支付" @submit="onSubmit" />



</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router';
import { useOrderDel } from '../store/orderDel';
import { useAddress } from '../store/user'
import { Toast } from 'vant'
import { payFail, paySuc, payAll } from '../api/orderDel';
const address = useAddress()
const Order = useOrderDel();
const router = useRouter()
const list = ref([]);
const loading = ref(false);
const finished = ref(true);
const route = useRoute()
const show1 = ref(false)
let idx = Number(route.params.idx)
const handleEidt = () => {
  router.push({
    path: '/addresslist'
  })
}

const onLoad = () => {
  // 异步更新数据
  // setTimeout 仅做示例，真实场景中一般为 ajax 请求

}

const onClickLeft = () => history.back();

const checked = ref(true);
const checked1 = ref(false);

const show = ref(false);
const name = ref(null)
const actions = [
  { name: '无需餐具' },
  { name: '1份' },
  { name: '2份' },
  { name: '3份' },
];
const onCancel = () => { };

const onSelect = (item: any) => {
  console.log(item)
  name.value = item.name
}
const handleShow = () => {
  show.value = true
}

const message = ref();

const onSubmit = () => {
  show1.value = true
  // router.push({
  //   path: '/paysuccess'
  // })
};
interface List {
  img: string,
  objectId: string,
  price: string,
  name: string,
  num: string,
  id: string,
  n: Number,
  updateAt: string
}
let res: any = localStorage.getItem('carlist')
let res1: any = JSON.parse(res)
console.log(res1)
console.log(res)
const handleSuc = () => {
  router.push({
    path: '/paysuccess'
  })
  paySuc({ res1, status: '已完成' })
  payAll({ res1, status: '已完成' })
  localStorage.removeItem('carlist')
}
const handleFal = () => {
  router.push({
    path: '/payfail'
  })
  payFail({ res1, status: '未付款' })
  payAll({ res1, status: '未付款' })
  localStorage.removeItem('carlist')
}






</script>

<style lang="scss" scoped>
.content {
  padding: 30px 10px 100px;
  display: flex;
  justify-content: space-around;
}

.pop {
  height: 30px;
}

.eject {
  height: 300px;

  .message {
    height: 100px;
    border: 1px solid gray;
  }

  .request {
    font-size: 18px;
  }
}


.orderDel {
  height: 30px;
  line-height: 30px;
  font-size: 3rem;
}

.user {
  margin-top: 46px;
  height: 60px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid gray;
  border-bottom: 1px solid gray;
  // background-color: aqua;

  .left {
    font-size: 5rem;
  }

  .middle {
    position: relative;
    left: -35px;
    height: 62px;
  }

  .right {
    font-size: 5rem;
  }
}

.limit {
  display: flex;
  height: 60px;
  justify-content: space-around;
  align-items: center;
  // background-color: aqua;

  .left {
    font-size: 5rem;
    position: relative;
    left: -10px;
  }

  .middle {
    font-size: 3rem;
    position: relative;
    left: -68px;
  }

  .right {
    font-size: 5rem;
  }
}

.empty {
  height: 10px;
  background-color: rgb(235, 239, 239);
}

.time {
  width: 100%;
  height: 60px;
  background-color: rgb(235, 239, 239);
  display: flex;
  align-items: center;

  .tip {
    line-height: 30px;
    text-align: center;
    width: 100%;
    background-color: #fff;
    color: red;
    font-size: 2.8rem;
  }
}

.bbox {
  width: 100%;
  // border-top: 1px solid rgb(161, 163, 163);
  border-bottom: 1px solid rgb(161, 163, 163);

}

.box {
  width: 343.33px;
  line-height: 30px;
  margin: 0 auto;
}

.flex1 {
  display: flex;
  justify-content: space-between;
  font-size: 18px;

}

.gray {
  color: gray;
}

.Allprice {
  height: 50px;
  line-height: 50px;
  float: right;
  font-size: 20px;
  margin-right: 30px;
  // background-color: skyblue;
}

.red {
  color: red;
}

.box2 {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid rgb(161, 163, 163);
}

.icon {
  font-size: 30px;
}
</style>